﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model.WaiGaoQiao;
using WaiGaoQiaoWeb.Models;
using WaiGaoQiaoWeb.JsonEntities;
using AutoMapper;
using System.Data;

namespace WaiGaoQiaoWeb.Controllers
{
    public class PasswordModifyController : Controller
    {
        private PasswordModifyInfo yaxinfo = new PasswordModifyInfo();
        public ActionResult PasswordModifyIndex()
        {
            return View();
        }

        public ActionResult SavePassword(PasswordModifyVM model)
        {
            int result = 0;
            if (ModelState.IsValid)
            {
                string name = ((LogOnModel)(System.Web.HttpContext.Current.Session["user"])).LogName;
                object[] yax = new object[] { name, model.passwords };
                result = yaxinfo.SavePassword(yax);
            }
            return Json(result);
        }

        /// <summary>
        /// 验证新密码与确认新密码是否相符
        /// </summary>
        /// <param name="passwords"></param>
        /// <param name="passwordsEnter"></param>
        /// <returns></returns>
        public ActionResult CheckPasswords(string passwords, string passwordsEnter)
        {
            return Json(passwords == passwordsEnter ? true : false);
        }

        /// <summary>
        /// 验证旧密码是否正确
        /// </summary>
        /// </summary>
        /// <param name="PassWordsOld"></param>
        /// <param name="PasswordsEdit"></param>
        /// <returns></returns>
        public ActionResult CheckPasswordsOld(string PassWordsOld)
        {
            string name = ((LogOnModel)(System.Web.HttpContext.Current.Session["user"])).LogName;
            string oldpassword = yaxinfo.CheckPasswordsOld(name);
            return Json(PassWordsOld == oldpassword ? true : false);
        }
    }
}
